const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}
const strhex = str => {
  str = str.toLowerCase();
  let newBuffer = new ArrayBuffer(str.length / 2);
  let hexBuffer = new Uint8Array(newBuffer, 0);
  let h = 0,
    l = 0;
  for (let i = 0; i < str.length / 2; i++) {
    h = str.charCodeAt(2 * i);

    l = str.charCodeAt(2 * i + 1);
    if (48 <= h && h <= 57) {
      h = h - 48;
    } else {
      h = h - 97 + 10;
    }
    if (48 <= l && l <= 57) {
      l = l - 48;
    } else {
      l = l - 97 + 10;
    }
    hexBuffer[i] = h * 16 + l;
  }
  return hexBuffer;
}
const myHextoString = hex=> {
  let out = '';
  for (let i = 0; i < hex.length; i++) {
    let h = (hex[i] / 16);
    if (h >= 10) {
      h = h - 10 + 97;
    } else {
      h = h + 48;
    }
    h = String.fromCharCode(h);
    out += h;

    let l = hex[i] % 16;
    if (l >= 10) {
      l = l - 10 + 97;
    } else {
      l = l + 48;
    }
    l = String.fromCharCode(l);
    out += l;

  }
  return out
}
module.exports = {
  formatTime: formatTime,
  strhex: strhex
}
